<template>
	<view>
		<button style="background-color: #2B85E4; width: 80%; margin-top: 220rpx;" @click="btn">点击进行人脸验证</button>
		 <view class="content">
		        <button type="primary" @click="checkIsSupportSoterAuthentication">检查支持的认证方式</button>
		        <button type="primary" @click="checkIsSoterEnrolledInDeviceFingerPrint">检查是否录入指纹</button>
		        <button type="primary" @click="checkIsSoterEnrolledInDeviceFaceID">检查是否录入FaceID</button>
		        <button type="primary" @click="startSoterAuthenticationFingerPrint">开始指纹认证</button>
		        <button type="primary" @click="startSoterAuthenticationFaceID">开始FaceID认证</button>
		    </view>
	</view>
</template>

<script>
	import * as api from '@/api/api.js'
	export default {
		data() {
			return {
				img: '',
				img1:''
			}
		},
		methods: {
			btn() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //拍照
					success: function(res) {
						this.img = res.tempFilePaths[0]
						console.log(this.img)
						const uploadTask = uni.uploadFile({
							url: 'https://xiuqiu.xiuqiu.cc/api/app/file/upload/element', // 这里加上图片上传的地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: (uploadFileRes) => {
								this.img1 = "http://cdn.jiaoyou.zheyousoft.cn/"+uploadFileRes.data;
								console.log(this.img1)
								// let datas = JSON.parse(uploadFileRes.data); //这里面就是后台返回来的图片路径
								// console.log(datas)
								api.request({
									url: '/p/user/faceVerify',
									method: "GET",
									data: {
										submitPath: this.img1
									},
								}).then(res => {
									console.log(res)
									if (res.statusCode == 200) {
										uni.showToast({
											icon: 'none',
											title: '登录成功'
										});
										setTimeout(() => {
											uni.reLaunch({
												url: '../index/index'
											});
										}, 1000)
									} else {
										uni.showToast({
											icon: 'none',
											title: '验证失败'
										});
									}
								})
							},
							fail: (err) => {
								uni.hideLoading();
								uni.showToast({
									title: "网络已断开",
									icon: "none"
								})
							}
						});


						// api.request({
						// 	url: "/p/main/loc",
						// 	method: 'GET'
						// }).then(res=>{
						// 	console.log(res)
						// })
						console.log(this.img1)
						// api.request({
						// 	url: '/p/user/faceVerify',
						// 	method: "GET",
						// 	data: {
						// 		submitPath: this.img1
						// 	},
						// }).then(res => {
						// 	console.log(res)
						// 	if (res.statusCode == 200) {
						// 		uni.showToast({
						// 			icon: 'none',
						// 			title: '登录成功'
						// 		});
						// 		setTimeout(() => {
						// 			uni.reLaunch({
						// 				url: '../index/index'
						// 			});
						// 		}, 1000)
						// 	} else {
						// 		uni.showToast({
						// 			icon: 'none',
						// 			title: '验证失败'
						// 		});
						// 	}
						// })

					},
					fail: function(res) {
						console.log('调取失败')
					}
				});
			},
			 checkIsSupportSoterAuthentication() {
			                uni.checkIsSupportSoterAuthentication({
			                    success(res) {
			                        console.log(res);
			                    },
			                    fail(err) {
			                        console.log(err);
			                    },
			                    complete(res) {
			                        console.log(res);
			                    }
			                })
			            },
			            checkIsSoterEnrolledInDeviceFingerPrint() {
			                uni.checkIsSoterEnrolledInDevice({
			                    checkAuthMode: 'fingerPrint',
			                    success(res) {
			                        console.log(res);
			                    },
			                    fail(err) {
			                        console.log(err);
			                    },
			                    complete(res) {
			                        console.log(res);
			                    }
			                })
			            },
			            checkIsSoterEnrolledInDeviceFaceID() {
			                uni.checkIsSoterEnrolledInDevice({
			                    checkAuthMode: 'facial',
			                    success(res) {
			                        console.log(res);
			                    },
			                    fail(err) {
			                        console.log(err);
			                    },
			                    complete(res) {
			                        console.log(res);
			                    }
			                })
			            },
			            startSoterAuthenticationFingerPrint() {
			                uni.startSoterAuthentication({
			                    requestAuthModes: ['fingerPrint'],
			                    challenge: '123456',
			                    authContent: '请用指纹解锁',
			                    success(res) {
			                        console.log(res);
			                    },
			                    fail(err) {
			                        console.log(err);
			                    },
			                    complete(res) {
			                        console.log(res);
			                    }
			                })
			            },
			            startSoterAuthenticationFaceID() {
			                uni.startSoterAuthentication({
			                    requestAuthModes: ['facial'],
			                    challenge: '123456',
			                    authContent: '请用FaceID解锁',
			                    success(res) {
			                        console.log(res);
			                    },
			                    fail(err) {
			                        console.log(err);
			                    },
			                    complete(res) {
			                        console.log(res);
			                    }
			                })
			            }
			

		}
	}
</script>

<style>

</style>
